@extends('admin/index')
@section('name')
    <h1><span class="label label-default"> 链接管理  </span></h1>
    <hr>

    <table class="table table-bordered  table-hover" id="tent">
        <tr>
            <th>ID</th>
            <th>名称</th>
            <th>链接</th>
            <th>图片</th>
            <th>操作</th>
        </tr>
        @foreach($result as $v)
            <tr>
                <td>{{$v->id}}</td>
                <td>{{$v->name}}</td>
                <td>{{$v->url}}</td>
                <td>
                    <img src="{{$v->img}}" width="50px"></td>
                <td>
                    <a href="/adm/link/upd/{{$v->id}}" class="btn btn-info">编辑</a>
                    <button class="btn btn-danger" onclick="del({{$v->id}})">删除</button>
                </td>
            </tr>
        @endforeach
    </table>

    <script>
        function del($id) {
            var id = $id;

            $.ajax({
                type: 'get',
                url: "{{url('/adm/link/del')}}/" + id,
                data: id, //发送请求数据
                success: function (data) {
                    console.log(data);
                    if (data == 1) {
                        $("table#tent tr").click(function () {
                            $(this).remove();
                        });
                        window.location.href='{{url('/adm/link')}}';
                    } else {
                        alert('删除失败');
                    }
                },
                error:function () {
                    alert('ajax请求失败');
                }
            });
        }
    </script>

@endsection
